<template>
  <div class="search-bar">
    <el-form :inline="true" :model="formItem" class="form-filter" size="mini">
      <el-form-item>
        <el-input
          v-model="formItem.s_name"
          clearable
          placeholder="请输入任务名称/编号..."
          @keyup.enter.native="search"
          @change="onMixedInputChange"
        />
      </el-form-item>
      <el-form-item>
        <el-button size="mini" plain icon="el-icon-search" @click="search" />
      </el-form-item>
    </el-form>
  </div>
</template>
<script>

// 定义一个查询表单原始项
const formItem = {
  s_name: '',
  s_code: ''
}

export default {
  name: 'StopServiceNoticeTableFilter',
  data() {
    return {
      /** CMDB模型树 */
      cmdbModels: null,
      formItem: {
        ...formItem
      },
      select: '',
      placeholder: ''
    }
  },
  mounted() {

  },
  methods: {
    search: function() {
      this.formItem.s_code = this.formItem.s_name
      this.$parent.filter(this.formItem)
    },
    reset: function() {
      this.formItem = {
        ...formItem
      }
      this.search()
    },
    onMixedInputChange(value) {
      if (value === '') {
        this.search()
      }
    },
    onMixedSelectChange(value) {
      this.options.find((option) => {
        if (option.value === value) {
          this.placeholder = '请输入' + option.label
        }
        this.formItem[option.value] = ''
      })
      if (value === '') {
        this.search()
        this.placeholder = ''
      }
    },
    onTypeChange(value) {
      this.search()
    }
  }
}
</script>
